package org.example.swagger01.config;

import com.google.common.base.Predicates;
import org.example.swagger01.anno.MyAnnotation4Swagger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
import springfox.documentation.spring.web.plugins.Docket;


/**
 * @author admin
 * @version 1.0.0
 * @ClassName SwaggerConfiguration.java
 * @Description TODO
 * @createTime 2021年04月17日 10:48:00
 */
@Configuration
public class SwaggerConfiguration {


    /**
     * Docket是Swagger2的全局配置对象
     * @return
     */
    @Bean
    public Docket docket(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2);//版本是Swagger2
        ApiInfo apiInfo = new ApiInfoBuilder().contact(new Contact(
                "于文华Swagger开发文档",//文档发布者名称
                "http://www.baidu.com",//文档发布者企业名称
                "1010@qq.com"//发布者邮箱
        )).title("Swagger学习").build();
        docket.apiInfo(apiInfo);
        final Docket build = docket.select().apis(RequestHandlerSelectors.basePackage("org.example.swagger01.controller"))//构建选择器
                .apis(Predicates.not(RequestHandlerSelectors.withMethodAnnotation(MyAnnotation4Swagger.class)))
//                .paths(PathSelectors.regex("/ss/.*")) //路径地址约束
//                .paths(Predicates.or(PathSelectors.regex("/"),PathSelectors.regex("")))
                .build();

        return build;

    }

}
